Learning Flex Basics (Part 3) : Working with Containers
Table of Contents
- Introduction
- Building the Containers
- Create the Application Object
- Create a Data Array
- Add a TabNavigator Container for Global Navigation
- Add an HBox and Panel Containers for Main Views
- Add a ViewStack, LinkBar, and Panel Containers for Secondary Views
- Add a Form Container
- Add a Tile Layout Container and Populate It Using a Repeater
- Create a Pseudo Bar Chart Using a Repeater and VBoxes
- Complete Code Listing for containers.mxml
- Where to Go from Here
Add a Form Container
The navigation of our simple application is now complete, and for the rest of the tutorial you focus on the use of layout containers. First, you create a Form container, which automatically arranges form controls and also provides some aids for handling the processing of form data (which you won't use here, but are straightforward and covered in the Flex documentation). You can use ordinary event handlers for form data also, as you do in this exercise.
The Form works with two nested container classes:
- FormHeading: Creates one or more headings (this is optional - you can use Labels as well)
- FormItem: Creates labels for a control or a group of controls
Inside the Form, you use a ComboBox, similar to an HTML select control. The ComboBox is covered in more detail in Learning Flex Basics (Part 1): Creating Your First Flex Application. The ComboBox items are generated from an array of simple values or objects; here, you use the array you created in the Script block earlier.
You also create a ControlBar container in this section. A ControlBar is an optional footer container for a Panel with a horizontal layout.
-
Inside the Panel with the title "Form," add a Form container:
<mx:Form> </mx:Form>
-
Inside the Form, add a FormHeading with the label My Form:
<mx:FormHeading label="My Form"/>
-
After the FormHeading, add a FormItem container block with the label Pick a Number:
<mx:FormItem label="Pick a Number"> </mx:FormItem>
-
Inside the FormItem, add a ComboBox with the
idof myCombo and the dataProvider property bound tomyArray:<mx:ComboBox id="myCombo" dataProvider="{myArray}"/> -
After the Form container, but still inside the Panel, add a ControlBar container:
<mx:ControlBar>
</mx:ControlBar> -
Inside the ControlBar container, add a Label whose text is the string "You chose: " joined to a binding to the
selectedItemproperty of the ComboBox:<mx:Label text="You chose: {myCombo.selectedItem}"/> - Save the file and browse it to see the form; select an different item in the ComboBox to see the Label in the ControlBar container change.